package com.db.report.demo;

import com.db.report.Report;

/**
 * @author nulls.narik
 */
public class DemoReport {

    private static int search(String[] args, String arg) {
        int index = 0;
        for (String value : args) {
            if (arg.equals(value))
                return index;
            index++;
        }
        return -1;
    }

    private static final String PORT_FOR_CLIENT_KEY = "-port_client";
    private static final String PORT_FOR_EXCHANGE_KEY = "-port_exchange";

    public static void main(String[] args) {
        int portForClient = 4000;
        int portForExchange = 5000;

        int index = search(args, PORT_FOR_CLIENT_KEY);
        if (index >= 0 && index < args.length - 1) {
            try {
                portForClient = Integer.valueOf(args[index + 1]);
            } catch (NumberFormatException exception) {
                portForClient = 4000;
            }
        }

        index = search(args, PORT_FOR_EXCHANGE_KEY);
        if (index >= 0 && index < args.length - 1) {
            try {
                portForExchange = Integer.valueOf(args[index + 1]);
            } catch (NumberFormatException exception) {
                portForExchange = 5000;
            }
        }

        Report report = new Report();
        report.connect(portForClient, portForExchange);

    }
}
